<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>todolist业务</title>
    <script src="./资源/Vue/vue.js"></script>
    <style>
        .box {
            width: 500px;
            margin: 0 auto;
        }

        .seek {
            width: 100%;
            height: 50px;
            font-size: 0;
        }

        .seek input {
            height: 50px;
            width: 400px;
            box-sizing: border-box;
            vertical-align: top;
            font-size: 20px;
            padding-left: 10px;
        }

        .seek button {
            width: 100px;
            height: 50px;
            box-sizing: border-box;
            font-size: 20px;
        }
        
        .plan {
            font-size: 18px;
            font-weight: bold;
            margin: 10px 0;
        }

        .list {
            font-size: 18px;
            font-weight: bold;
            margin: 10px 0;
        }

        .list ul {
            margin: 0;
            padding: 0;
            list-style: none;
        }

        .list ul li {
            width: 100%;
            height: 40px;
            /* background-color: aqua; */
            margin-top: 10px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            border-bottom: 1px solid #000;
            font-weight: normal;
            padding: 0 15px;
        }

        .list ul li input {
            width: 20px;
            height: 20px;
        }

        .list ul li span {
            vertical-align: top;
        }

        .list ul li button {
            padding: 5px 10px
        }
        .list ul li button:hover{
            background-color: red;
        }
    </style>
</head>

<body>
    <div id="app">
        <div class="box">
            <div class="seek">
                <input type="text" placeholder="请输入内容" v-model="value" v-on:keydown.enter="btn">
                <button v-on:click="btn">确认</button>
            </div>
            <div class="plan">计划列表 [<span>{{num}}</span>]</div>
            <div class="unfinished list">
                <div class="title">未完成 [<span>{{num1}}</span>]</div>
                <ul>
                    <li v-for="(item,index) in arr" v-bind:key="item.id" v-if="!item.isShow">
                        <div>
                            <input type="checkbox" v-model="arr[index].isShow">
                            <span>{{item.value}}</span>
                        </div>
                        <button v-on:click="remove(index)">删除</button>
                    </li>
                </ul>
            </div>
            <div class="done list">
                <div class="title">已完成 [<span>{{num2}}</span>]</div>
                <ul>
                    <li v-for="(item,index) in arr" v-bind:key="item.id" v-if="item.isShow">
                        <div>
                            <input type="checkbox"  v-model="arr[index].isShow">
                            <span>{{item.value}}</span>
                        </div>
                        <button v-on:click="remove(index)">删除</button>
                    </li>
                </ul>
            </div>
        </div>
    </div>

    <script>
        
        new Vue({
            el: "#app",
            data: {
                value: "",
                arr: [],
                obj: {}
            },
            methods: {
                btn() {
                    // console.log("this的指向=>",this);
                    if (this.value.length == 0) return alert("内容不能为空");


                    let obj = {};
                    obj.isShow = false;
                    obj.value = this.value;
                    obj.id = Symbol();
                    this.arr.push(obj);
                    this.value = "";

                    // 这两种清空对象的方式有什么区别？
                    // 可能生命周期的问题

    
                    // this.obj = {};
                    // this.obj.isShow = false;
                    // this.obj.value = this.value;
                    // this.obj.id = Symbol();
                    // this.arr.push(this.obj);
                    // this.value = "";
                },
                remove(index){
                    this.arr.splice(index,1);
                }
            },
            computed: {
                num() {
                    let num = 0
                    num = this.arr.length
                    return num
                },
                num1() {
                    let num = 0
                    this.arr.forEach(item => {
                        if (!item.isShow) {
                            ++num
                        }
                    })
                    return num
                },
                num2() {
                    let num = 0
                    this.arr.forEach(item => {
                        if (item.isShow) {
                            ++num
                        }
                    })
                    return num
                }


            }

        })

    </script>
</body>

</html>